#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

const int MAXN = 5e5+10;
int n,m,fa[MAXN];
struct edge{
	int x,y,val,fx,fy,num;
	friend bool operator < (edge a,edge b){
		return a.val < b.val;
	}
}e[MAXN],t[MAXN];

bool cmp(edge a,edge b){return a.num < b.num;}

int gf(int x){return fa[x] == x ? x:fa[x] = gf(fa[x]);}

void unionn(int x,int y){fa[gf(x)] = gf(y);}

int main (){
	n = in,m = in;
	for(int i = 1;i <= n;i++) fa[i] = i;
	for(int i = 1;i <= m;i++){
		e[i].x = in,e[i].y = in;e[i].val = in,e[i].num = i;
	}
	sort(e+1,e+m+1);
	for(int i = 1;i <= m;){
		int j = i;
		while(j <= m && e[i].val == e[j].val){
			e[j].fx = gf(e[j].x);e[j].fy = gf(e[j].y);
			j++;
		}
		for(;i < j;i++){
			if(i < j && gf(e[i].x) != gf(e[i].y)){
				unionn(e[i].x,e[i].y);
			}
		}
	}
	sort(e+1,e+m+1,cmp);
	for(int i = 1;i <= n;i++) fa[i] = i;
	int q = in;
	while(q--){
		int tot = in;bool f = 1;
		for(int i = 1;i <= tot;i++){
			int num = in;
			t[i] = {e[num].fx,e[num].fy,e[num].val,0,0,0};
		}
		sort(t+1,t+tot+1);
		for(int i = 1;i <= tot && f;){
			int j = i + 1;
			if(t[i].x == t[i].y) f = 0;
			unionn(t[i].x,t[i].y);
			while(j <= tot && t[j].val == t[i].val){
				if(gf(t[j].x) == gf(t[j].y)){
					f = 0;break;
				}
				else unionn(t[j].x,t[j].y),j++;
			}
			for(;i < j;i++){
				fa[t[i].x] = t[i].x;
				fa[t[i].y] = t[i].y;
			}
			i = j;
		}
		if(f) puts("YES");
		else puts("NO");
	}
	return 0;
}
